[##include file="common/header.tpl.php"##]
[##include file="common/nav.tpl.php"##]

<div id="main">
	<div style="padding:0 0 20px 0; line-height:25px;">
		<form method="POST" action="[##$adminurl##]/?m=material&a=upimage" enctype="multipart/form-data" id="upimg_form" name="upimg_form">
			<strong>上传图片</strong><br />
			目录：
			<select name="upimg_folder_prefix">
				<option value="/app/factory">疯狂工厂</option>
				<option value="/app/21">21点</option>
			</select><br />
			下级目录：<input type="text" style="width:300px" name="upimg_subfolder" /><br />
			随机文件名：<input type="checkbox" name="upimg_random_name" /> &nbsp; <span style="color:#aaa; font-size:11px;">(不选中，则按上传时的文件名)</span><br />
			宽：<input type="text" style="width:50px" name="upimg_width" /> ， 高：<input type="text" style="width:50px" name="upimg_height" /> <span style="color:#aaa; font-size:11px;">(不填则按原图尺寸，填了则按等比例压缩)</span><br />
			<input type="file" name="upimg" size="50" /><br />
			<input type="submit" value="上传" style="padding:5px 20px; font-weight:bold;" />
		</form>
	</div>

	<table class="gridView" style="font-size:10px">
		<thead>
			<tr>
				<td style="width:30px">ID</td>
				<td>预览</td>
				<td style="width:200px">图片地址</td>
				<td style="width:60px">上传时间</td>
				<td style="width:40px">大小</td>
				<td style="width:60px">尺寸</td>
				<td style="width:35px">上传人</td>
				<td style="width:30px">操作</td>
			</tr>
		</thead>
		[##foreach from=$list item=item##]
		<tr id="image_[##$item.id##]">
			<td>[##$item.id##]</td>
			<td><a href="[##$siteurl##]/image[##$item.name##]" target="_blank"><img src="[##$siteurl##]/image[##$item.name##]" class="resize" /></a></td>
			<td><a href="[##$siteurl##]/image[##$item.name##]" target="_blank">[##$item.name##]</a></td>
			<td>[##$item.time|formatTime:'Y-m-d H:i:s'##]</td>
			<td[##if $item.size > 50##] style="color:red;font-weight:bold;"[##/if##]>[##$item.size##]K</td>
			<td>[##$item.width##] x [##$item.height##]</td>
			<td>[##$item.uin##]</td>
			<td><a href="#" onclick="delete_image([##$item.id##]); return false;">删除</a></td>
		</tr>
		[##/foreach##]
	</table>
	
	[##$image_count|Pager:$perpage##]
</div>

<script type="text/javascript">
$(document).ready(function() {
	$('img.resize').each(function() {
		var maxWidth = 120; // Max width for the image
		var maxHeight = 120;	// Max height for the image
		var width = $(this).width();	// Current image width
		var height = $(this).height();  // Current image height
		// Check if the current width is larger than the max
		if(width >= height && width > maxWidth) {
			ratio = maxWidth / width;   // get ratio for scaling image
			$(this).css("width", maxWidth); // Set new width
			$(this).css("height", height * ratio); // Scale height based on ratio
		} else if(height >= width && height > maxHeight) {
			ratio = maxHeight / height; // get ratio for scaling image
			$(this).css("height", maxHeight);   // Set new height
			$(this).css("width", width * ratio);	// Scale width based on ratio
		}
	});
});

function delete_image(id) {
	if( confirm('确定要删除这张图片吗吗？') ) {
		var submit_url = '[##$adminurl##]/?m=material&a=delete';
		$.post(submit_url , {'image_id' : id} , function(d) {
			if(d.code) return alert(d.msg);

			alert(d.msg);
			$('#image_' + id).fadeOut();
		} , 'json');
	}
}
</script>

[##include file="common/footer.tpl.php"##]